import { Button, Checkbox, Form, Input } from "antd";
import {
    useNavigate
} from "react-router-dom"
import http from '../../utils/fetchHttp'
import './index.scss'


const Login = () => {
const navigator=useNavigate();
const onFinish = (values) => {
  console.log("Success:", values);
  http({
    url:'/noToken/login',
    method: 'post',
    data:{
        email:values.emails,
        password:values.password
    }
}).then((res=>{
    console.log(res);
    if(res.code==200){
        sessionStorage.setItem("token",JSON.stringify(res.token))
        console.log(res.data[0].user_sex);
        if(res.data[0].user_sex=="0"){
          res.data[0].user_sex="男"
          sessionStorage.setItem("userInfo",JSON.stringify(res.data))
        }else{
          res.data[0].user_sex="女"
          sessionStorage.setItem("userInfo",JSON.stringify(res.data))
        }
        navigator("/index")
    }

}))
};
const onFinishFailed = (errorInfo) => {
  console.log("Failed:", errorInfo);
};
return (
  <div className={"loginBox"}>
    <Form
  className={"loginForm"}
    name="basic"
    labelCol={{
      span: 8,
    }}
    wrapperCol={{
      span: 16,
    }}
    style={{
        maxWidth: 600,
    }}
    initialValues={{
      remember: true,
    }}
    onFinish={onFinish}
    onFinishFailed={onFinishFailed}
    autoComplete="off"
  >
    <Form.Item
      label="Emails"
      name="emails"
      rules={[
        {
          required: true,
          message: "Please input your username!",
        },
      ]}
    >
      <Input />
    </Form.Item>

    <Form.Item
      label="Password"
      name="password"
      rules={[
        {
          required: true,
          message: "Please input your password!",
        },
      ]}
    >
      <Input.Password />
    </Form.Item>

   

    <Form.Item
      wrapperCol={{
        offset: 8,
        span: 16,
      }}
    >
      <Button type="primary" htmlType="submit">
        登录
      </Button>
    </Form.Item>
  </Form>
  </div>
)
};
export default Login;
